package com.wqtz.chechai.view.activities;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.presenter.BasePresent;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 :  Kisum
 * 创建时间: 2017/2/4
 * 查看合同页面
 */
public class ContractReviewActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.progressBar)
    ProgressBar mProgressBar;
    @BindView(R.id.tv_contract_info)
    TextView mTvContractInfo;
    private int pro = 0;
    private static final int MSG = 1;
    //创建一个Handler
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //处理消息
            switch (msg.what) {
                case MSG:
                    //设置滚动条的值
                    mProgressBar.setProgress(pro);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    public void init() {
        ButterKnife.bind(this);
        start();
    }

    @Override
    public void loadData() {

    }

    @Override
    public int setContentViews() {
        return R.layout.activity_contract_review;
    }

    @Override
    public BasePresent createPresenter() {
        return null;
    }

    @OnClick({R.id.iv_back,R.id.tv_contract_info})
    public void onClick(View view) {
        switch (view.getId()) {
            //返回放款详情页面
            case R.id.iv_back:
                Intent toLoanInfoIntent = new Intent(this, LoanInfoActivity.class);
                startActivity(toLoanInfoIntent);
                break;
            //合同信息
            case R.id.tv_contract_info:
                Intent toContractInfoIntent = new Intent(this, LoanContractInfoActivity.class);
                startActivity(toContractInfoIntent);
                break;
        }
    }

    /**
     * 开启进度条
     */
    private void start() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                int max = mProgressBar.getMax();
                try {
                    //子线程循环间隔消息
                    while (pro < max) {
                        pro += 1;
                        Message msg = new Message();
                        msg.what = MSG;
                        mHandler.sendMessage(msg);
                        Thread.sleep(20);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    @Override
    protected void onResume() {
        super.onResume();
        activitys.add(this); //添加当前的activity
    }
}
